
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package be.ac.ua.pats.thesisrobotica.robot.sensors;

//~--- non-JDK imports --------------------------------------------------------

import be.ac.ua.pats.thesisrobotica.robot.communication.Connection;
import be.ac.ua.pats.thesisrobotica.robot.communication.Sendable;

import lejos.nxt.comm.RConsole;

/**
 *
 * @author Admin
 */
public class SensorNotification extends Sendable {
    StringBuffer message = new StringBuffer();
    Connection   connection;
    String       prefix;
    String       suffix;

    public SensorNotification() {
        super();
    }

    public SensorNotification(Connection connection) {
        try {
            this.connection = connection;
        } catch (NumberFormatException e) {
            RConsole.println("NumberFormatException in SensorNotification()");
        }
    }

    public void setAndSend(String prefix, Object suffix) {
        try {
            Integer.parseInt(prefix);

            this.prefix = prefix;
            this.suffix = String.valueOf(suffix);

            this.send(connection);
        } catch (NumberFormatException e) {
            RConsole.println("NumberFormatException in SensorNotification()");
        }
    }

    public String encapsulate() {
        try {
            message = new StringBuffer();
            message.append(prefix).append(",").append(suffix);

            return message.toString();
        } catch (Exception e) {
            RConsole.println("Exception in SensorNotification:encapsulate");
            return "Error";
        } 
    }
}
